<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>编辑合作公司</title>
<link href="${rc.getContextPath()}/resources/css/common.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="${rc.getContextPath()}/resources/js/jquery.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/common.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/jquery.validate.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/messages_cn.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/resources/js/input.js"></script>
<script type="text/javascript" src="${rc.getContextPath()}/js/ajaxupload.js"></script>

<!-- 引入弹出JS begin -->
<script type="text/javascript" src="${rc.getContextPath()}/js/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript">
	var base = '${rc.getContextPath()}';
	function saveCompany() {
		var form1 = $("#tableForm");
		editor.sync();
		form1.submit();
	}
	function myAlert(txt) {
		window.parent.$.dialog({
			lock : true,
			content : txt,
			cancelVal : '确定',
			autoSize : true,
			cancel : function() { //请求成功后处理函数。 
			}
		});
	}
	$(document).ready(function() {
		var msg = $("#msg").val();
		if (msg == "success") {
			$.dialog.alert("保存成功");
		} else if (msg == 'failed') {
			$.dialog.alert("保存失败");
		}

		var $inputForm = $("#tableForm");
		$inputForm.validate({
			errorClass : "fieldError",
			rules : {
				companyName : "required",
				rank : {required:true,number:true},
				linkUrl : 'url',
				email:'email'
			}
		});
		
		initUploadButton('btnUpload');
		var url = "${company.imgUrl}";
		if (!url) {			
			$("#companyImg").css("display","none");//如果没图片，就不显示图片框
		}
		
		var isForMember = "${company.isForMember}";
		if (isForMember == "true") {
			document.getElementById("chkIsForMember").checked = true;
		}
	});
	
	function initUploadButton(buttonId){
		var button = $("#"+buttonId);
		var exts = "jpg|png|gif",paths = "|";
		new AjaxUpload(button,
		{   
   			action: '${base}/company/admin/uploadImage.html',   
   			name: 'uploadFile',
    		onSubmit : function(file, ext)
    		{     
           		if ( !RegExp( "\.(?:" + exts + ")$$", "i" ).test(file) ) 
           		{
           			$.dialog.alert("只能上传以下类型：" + exts).zindex();
					return false;
				}          		         
   		 	},   
   		 	onComplete: function(file, response,statusText)
   		 	{   
				var response = jQuery.parseJSON(response);
   		 		if(response.status=="error")
				{
   		 			$.dialog.alert("上传失败！") ;
				}
				else 
				{
					var res = eval(response);
					if (res.result) {
						$("#companyImg").attr("src","${base}" + response.path);
						$("#companyImg").css("display","block");
						$("#hidImageUrl").val(response.path);
						$("#txtLocalUrl").val(file);
						$.dialog.alert("上传成功！") ;
					} else {
						$.dialog.alert("上传失败，请重试！") ;
					}
				}
    		}   
		}); 
	}
	
	function preview() {
		var form = document.getElementById("tableForm");
		var url = form.action;
		form.target='_blank';
		form.action = '${base!}/front/directorypreview.html';
		form.submit();
		
		form.action = url;
		form.target = "_self"
	}
	
	function saveCompany() {
		$('#tableForm').submit();
	}
	
	function goBackToList() {
		var url = "${rc.getContextPath()}/company/admin/list.html";
		location.href = url;
	}
</script>
<script type="text/javascript">
	var base = '${base}';
</script>
<script type="text/javascript" src="${rc.getContextPath()}/js/ckeditor/ckeditor.js"></script>
</head>

<body>
	<input type="hidden" id="msg" name="msg" value="${msg!}" />
	<div class="path">
		<a href="#"><b>编辑合作公司</b></a>
	</div>
	<form action="${base!}/company/admin/saveCompany.html" method="post" id="tableForm" name="tableForm" enctype="multipart/form-data">
		<input type="hidden" name="companyId" value="${company.companyId}"/>
		<table class="input tabContent">
			<tbody>
				<tr>
					<th><span class="requiredField">*</span>公司名称:</th>
					<td>
						<input type="text" name="companyName" value="${company.companyName}" style="width: 300px" />
					</td>
				</tr>
				<tr>
					<th><span class="requiredField">*</span>排序:</th>
					<td>
						<input type="text" id="txtRank" name="rank" value="${company.rank}" style="width: 300px" />
					</td>
				</tr>
				<tr>
					<th>会员专享:</th>
					<td>
						<input type="checkbox" name="isForMember" value="true" id="chkIsForMember"/>
					</td>
				</tr>
				<tr>
					<th>公司链接:</th>
					<td>
						<input type="text" name="linkUrl" value="${company.linkUrl}" style="width: 300px" />（格式：http://www.xxx.com）
					</td>
				</tr>
				<tr>
					<th>联系电话:</th>
					<td><input class="w150" type="text" name="telephone" value="${company.telephone}" style="width: 300px" /></td>
				</tr>
				<tr>
					<th>电子邮件:</th>
					<td><input class="w150" type="text" name="email" value="${company.email}" style="width: 300px" /></td>
				</tr>
				<tr>
					<th>公司地址:</th>
					<td><input class="w150" type="text" name="address" value="${company.address}" style="width: 640px"/></td>
				</tr>
				<tr>
					<th>中文地址:</th>
					<td><input class="w150" type="text" name="linkMan" value="${company.linkMan}" style="width: 640px" /></td>
				</tr>
				<tr>
					<th>公司简介:</th>
					<td colspan="3">
							<textarea rows="30" cols="50" name="description" id = "ueditTxt" >${company.description!}</textarea>
				            <script type="text/javascript">CKEDITOR.replace('description');</script>
					</td>						
				</tr>
				<tr>
					<th>ICON图标:</th>
					<td>
						<select name="iconId">
							<option value=""></option>
							<#if icons?? && icons?size gt 0>
								<#list icons as ic>
									<option value="${(ic.iconId)!}" <#if company.iconId?? && company.iconId==ic.iconId> selected="selected"</#if>>${(ic.title)!}</option>
								</#list>
							</#if>
						</select>
					</td>
				</tr>
				<tr>
					<th>图片:</th>
					<td>
						<input type="text" id='txtLocalUrl' style="width: 300px"/>
						<input type="hidden" name="imgUrl" id="hidImageUrl" value="${company.imgUrl}"/>
						<input type="button" id="btnUpload" value="上传"/>
						<input type="button" value="清空" onclick="clearImage()"/>
					</td>
				</tr>
				<tr>
					<th>此处显示图片</th>
					<td>
						<img src="${base}${company.imgUrl}" alt="" id="companyImg"  width="200" height="200" />
					</td>
				</tr>
			</tbody>
		</table>

		<table class="input">
			<colgroup>
				<col width="15%" />
				<col width="35%" />
				<col width="15%" />
				<col width="35%" />
			</colgroup>
			<tr>
				<td></td>
				<td colspan="3">
					<input type="button" class="button" value="保存" onclick="saveCompany();" /> 
					<input type="button" class="button" value="预览 " onclick="preview();" />
					<input type="button" class="button" value="返回" onclick="goBackToList()" />
				</td>
			</tr>
		</table>
	</form>
</body>
</html>